package com.oa.tools.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.oa.tools.dao.PersonDAO;
import com.oa.tools.jobs.DynamicJob;
import com.oa.tools.utils.DateUtil;
import com.oa.tools.utils.ExcelUtil;
import com.oa.tools.utils.StringUtil;

@RestController
@RequestMapping(path = "flow")
public class OAFlowQueryController {
	

	@Autowired
	PersonDAO personDAO;
	
	public static final Logger logger = LoggerFactory.getLogger(DynamicJob.class);
	
	@RequestMapping({ "wyc/audit/export" })
	public void flowAuditList(HttpServletRequest request,HttpServletResponse response/*@RequestBody Map<String,Object> param*/) throws Exception {
		
		String titles [] = new String[] {"流程模板名称","审批状态","流程编号","申请人","申请部门","节点名称","操作者","操作人部门","操作类型","操作日期","操作时间","处理意见"};
		
		List<Map<String,Object>> dataMaps = personDAO.selectWYCFlowAuditBySql();
		
		List<List<String>> datas = new ArrayList<>();
		List<String> titleList = new ArrayList<>(); 
		for(String title:titles) {
			titleList.add(title);
		}
		datas.add(titleList);
		
		for(Map<String,Object> lineMap:dataMaps) {
			List<String> lineDataList = new ArrayList<>(); 
			for(int i = 0;i<titles.length;i++) {
				String title = titles[i];
				lineDataList.add(StringUtil.parseString(lineMap.get(title)));
			}
			datas.add(lineDataList);
		}
		
		ExcelUtil.exportExcel(response, "网约车流程审批记录"+DateUtil.curDayStr()+".xls", datas);
		
	}
	
}
